//==================================================================
//  Copyright (C) 2006  Davide Pasca
//
//  This library is free software; you can redistribute it and/or
//  modify it under the terms of the GNU Lesser General Public
//  License as published by the Free Software Foundation; either
//  version 2.1 of the License, or (at your option) any later version.
//
//  This library is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//  Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public
//  License along with this library; if not, write to the Free Software
//  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
//==================================================================
///
///
///
///
///
//==================================================================

#ifndef RANDOMIZER_H
#define RANDOMIZER_H

#include "psys.h"

//==================================================================
///
//==================================================================
class Randomizer
{
	u_int	_curval;

public:
	//==================================================================
	Randomizer( u_int seed=0 ) :
	  _curval( seed )
	{
	}

	//==================================================================
	void Reset( u_int seed )
	{
		_curval = seed;
	}
	//==================================================================
	u_int NextUInt()
	{
		_curval = _curval * 1664525 + 1013904223;
		_curval = (_curval >> 1) | (_curval << 31);
		return _curval;
	}
	//==================================================================
	float NextFloat()
	{
		u_int				temp;
		static const u_int	one = 0x3f800000;
		static const u_int	msk = 0x007fffff;

		_curval = _curval * 1664525 + 1013904223;
		_curval = (_curval >> 1) | (_curval << 31);

		temp = one | (_curval & msk);
		return (*(float *)&temp) - 1.0f;
	}
};

#endif